package com.ebupt.migu.music.schedule.service;

import com.ebupt.migu.common.pojo.Topic;
import com.ebupt.migu.common.push.MessageTopicBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liuyangyang@e-byte.com
 * @description: TODO
 * @date 2024/8/15 15:40
 */
@Service
@Slf4j
public class KafkaProducerService {

    private final KafkaTemplate<String, MessageTopicBean> kafkaTemplate;

    @Autowired
    public KafkaProducerService(KafkaTemplate<String, MessageTopicBean> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    public void sendMessage(Map<String, Object> strategy, String url, String request, String key_name, List<String> uids) {
        MessageTopicBean bean = new MessageTopicBean();
        bean.setKeyName(key_name);
        bean.setUrl(url);
        bean.setRequest(request);
        bean.setStrategy(strategy);
        bean.setUids(uids);
        if (Integer.valueOf(strategy.get("executeType").toString()) == 1) {
            kafkaTemplate.send(Topic.OFFLINE_MESSAGE, bean);
        } else {
            kafkaTemplate.send(Topic.OFFLINE_MESSAGE_TEST, bean);
        }
        log.info("message生产者bean-> {}", bean);
    }


}
